package com.me.demoanimation;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.Align;

public class labelTest implements ApplicationListener {
    Skin skin;
    Stage stage;
    SpriteBatch batch;
    Actor root;
    ShapeRenderer renderer;
    
	@Override
	public void create() {
		// TODO Auto-generated method stub
		batch = new SpriteBatch();
		renderer = new ShapeRenderer();
		skin = new Skin(Gdx.files.internal("data/uiskin.json"));
		skin.getAtlas().getTextures().iterator().next().setFilter(TextureFilter.Nearest , TextureFilter.Nearest);
		stage = new Stage(0,0,false);
		Gdx.input.setInputProcessor(stage);
		
		Table table = new Table();
		stage.addActor(table);
		table.setPosition(300, 65);
		table.debug();
		table.add(new  Label("this is regular text", skin));
		table.row();
		table.add(new Label("this is regular text\n with a new line" , skin));
		table.row();
		Label label3 = new Label("thiis is regular text\n with new line ,\nalign bottom, right",skin);
		label3.setAlignment(Align.bottom | Align.right);
		table.add(label3).minWidth(200).minHeight(110).fill();
		table.row();
		Label label4 = new Label("This is regular text with NO newlines, wrap enabled and aligned bottom, right.", skin);
		label4.setWrap(true);
		label4.setAlignment(Align.bottom | Align.right);
		table.add(label4).minWidth(200).minHeight(110).fill();
		table.row();
		Label label5 = new Label("This is regular text with\n\nnewlines, wrap\nenabled and aligned bottom, right.", skin);
		label5.setWrap(true);
		label5.setAlignment(Align.bottom | Align.right);
		table.add(label5).minWidth(200).minHeight(110).fill();
		table.pack();
		
	}

	@Override
	public void resize(int width, int height) {
		// TODO Auto-generated method stub
		stage.setViewport(width, height, false);
	}

	@Override
	public void render() {
		// TODO Auto-generated method stub
		
		Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		
		stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1/30f));
		stage.draw();
		Table.drawDebug(stage);
		
		float x=40, y=40;
		
		BitmapFont font = skin.getFont("default - font ");
		batch.begin();
		font.draw(batch,"the quick brown fox jumped out over the lazy cow", x, y);
		batch.end();
		
	    drawLine(x,y-font.getDescent(),x+1000,y-font.getCapHeight() + font.getDescent());
		
	}
	public void drawLine(float x1, float y1, float x2, float y2){
		renderer.setProjectionMatrix(batch.getProjectionMatrix());
		renderer.begin(ShapeType.Line);
		renderer.line(x1,y1,x2,y2);
		renderer.end();
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		stage.dispose();
		skin.dispose();
		
	}
	public boolean needsGL20(){
		return false;
	}

}

